package com.xiaojie.learn.util;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Data
@Accessors(chain = true)
    public class Beandd{
        @Excel(name="user_id",orderNum = "1")
        private String userId;
        @Excel(name="term_id",orderNum = "2")
        private String termId;
        @Excel(name="class_id",orderNum = "3")
        private String classId;

    public static void main(String[] args) throws IOException {
      /*  final FileInputStream fis = new FileInputStream("D:\\dataa.xls");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int len = 0;
        while ((len = fis.read(buffer) ) != -1){
            outputStream.write(buffer,0,len);
        }
        outputStream.close();
        fis.close();
        InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());*/
 /*       Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("1", "1"), Beandd.class, new ArrayList());
        OutputStream outputStream = new FileOutputStream("D:\\dataa0.xls");
        workbook.write(outputStream);*/

        List<Beandd> beandds = ExcelUtils.importExcel("D:\\dataa0.xls", 1, 1, Beandd.class);

        beandds.forEach(bean -> {
            if(StringUtils.isBlank(bean.getUserId())){
                return;
            }
            System.out.println(bean.getUserId() +"-"+bean.getClassId());
            JSONObject object = new JSONObject();
            object.put("userId",bean.getUserId());
            object.put("groupId",bean.getClassId());
            System.out.println(s);
        });

        List<Beandd> beandds1 = ExcelUtils.importExcel("D:\\dataa0.xls", 1, 1, Beandd.class);

        final Set<String> collect = beandds1.stream().map(Beandd::getUserId).collect(Collectors.toSet());

        collect.forEach(userId -> {
            System.out.println(userId);
            if(StringUtils.isBlank(userId)){
                return;
            }
            System.out.println(s);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

    }
    }